package com.doubi.controller.sysPermission;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.common.config.shiro.ShiroUtil;
import com.doubi.model.sys.TSysDept;
import com.doubi.model.sys.TSysUser;
import com.doubi.service.SysDeptRoleService;
import com.doubi.vo.AppModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("sysDeptRole")
public class SysDeptRoleController {

    @Autowired
    private SysDeptRoleService sysDeptRoleService;

    /**
     * 功能描述：保存或更新部门信息
     * @author   MrDoubi 2019-06-28 09:52
     * @param sysDept       TSysDept对象
     * @param roleOid       角色Oid
     * @return              返回AppModel对象
     */
    @SysLog(title = "保存或更新部门信息")
    @RequiresPermissions("sysDeptRole:saveOrUpdate")
    @PostMapping("saveOrUpdate")
    @ResponseBody
    public AppModel saveOrUpdate(TSysDept sysDept, String roleOid) {
        TSysUser sysUser = ShiroUtil.getUser();
        return new AppModel(0, "数据操作成功！", sysDeptRoleService.saveOrUpdate(sysDept, roleOid, sysUser));
    }

    /**
     * 功能描述：删除部门和下级部门
     * @author   MrDoubi 2019-06-28 09:34
     * @param oid       部门oid
     * @return          返回AppModel对象
     */
    @SysLog(title = "删除部门和下级部门")
    @RequiresPermissions("sysDeptRole:del")
    @PostMapping("del")
    @ResponseBody
    public AppModel del(String oid){
        TSysUser sysUser = ShiroUtil.getUser();
        return sysDeptRoleService.deleteBean(oid, sysUser);
    }

}
